//=============================================================================
// Heavy Gatlinggun - the monstrous big brother of the minigun...
//=============================================================================
class TFGunnerClass extends TFWeapon;

var     float           CurrentRoll;
var     float           RollSpeed;
//var     float           FireTime;
var() xEmitter          ShellCaseEmitter;
var() vector            AttachLoc;
var() rotator           AttachRot;
//var   int               CurrentMode;
var() float             GearRatio;
var() float             GearOffset;
var() float             Blend;

simulated function PostBeginPlay()
{
    Super.PostBeginPlay();

    if ( Level.NetMode == NM_DedicatedServer )
        return;

    ShellCaseEmitter = spawn(class'ShellSpewer');
	if ( ShellCaseEmitter != None )
	{
		ShellCaseEmitter.Trigger(Self, Instigator); //turn off
		AttachToBone(ShellCaseEmitter, 'shell');
	}
}

simulated function bool PutDown()
{
    if ( !tfhgunsiegem(firemode[1]).bsiegemode )
    {
        ReturnToIdle();
        return Super.PutDown();
    }

	//if ( Instigator.PendingWeapon == self )

	Instigator.PendingWeapon = self;
    return( false ); // Never let them put the weapon away.
}

simulated function OutOfAmmo()
{
    if ( !Instigator.IsLocallyControlled() || HasAmmo() )
        return;

	Instigator.AmbientSound = None;
    DoAutoSwitch();
}

simulated function Destroyed()
{
    if (ShellCaseEmitter != None)
    {
        ShellCaseEmitter.Destroy();
        ShellCaseEmitter = None;
    }

    Super.Destroyed();
}

simulated function SpawnShells(float amountPerSec)
{
    if(ShellCaseEmitter == None || !FirstPersonView())
        return;
	if ( Bot(Instigator.Controller) != None )
	{
		ShellCaseEmitter.Destroy();
		return;
	}

	ShellCaseEmitter.mRegenRange[0] = amountPerSec*2;
	ShellCaseEmitter.mRegenRange[1] = amountPerSec*2;
    ShellCaseEmitter.Trigger(self, Instigator);
}

simulated function bool FirstPersonView()
{
    return (Instigator.IsLocallyControlled() && (PlayerController(Instigator.Controller) != None) && !PlayerController(Instigator.Controller).bBehindView);
}

// Prevents wrong anims from playing
simulated function AnimEnd(int channel)
{
}

// Client-side only: update the first person barrel rotation
simulated function UpdateRoll(float dt, float speed, int mode)
{
    local rotator r;

    if (Level.NetMode == NM_DedicatedServer)
        return;

    //if (mode == CurrentMode) // to limit to one mode
    //{
       // log(self$" updateroll (mode="$mode$") speed="$speed);

        RollSpeed = speed;
        CurrentRoll += dt*RollSpeed;
        CurrentRoll = CurrentRoll % 65536.f;
        r.Roll = int(CurrentRoll);
        SetBoneRotation('Bone Barrels', r, 0, Blend);

        r.Roll = GearOffset + r.Roll*GearRatio;
        SetBoneRotation('Bone gear', r, 0, Blend);
    //}
}

simulated function bool StartFire(int mode)
{
    local bool bStart;

	if ( !TFHGunFire(FireMode[0]).IsIdle() || !TFHGunSiegeM(FireMode[1]).IsIdle())
		return false;

    //if(mode==0 && ammo[0].ammoamount==0) return false;

    bStart = Super.StartFire(mode);
    if(bStart) FireMode[mode].StartFiring();

    return bstart;
}

// Allow fire modes to return to idle on weapon switch (server)
simulated function DetachFromPawn(Pawn P)
{
    //log(self$" detach from pawn p="$p);

    ReturnToIdle();

    Super.DetachFromPawn(P);
}

simulated function ReturnToIdle()
{
    local int mode;

    for (mode=0; mode<NUM_FIRE_MODES; mode++)
    {
        if (FireMode[mode] != None)
        {
            FireMode[mode].GotoState('Idle');
        }
    }
}

defaultproperties
{
     AttachLoc=(X=-77.000000,Y=6.000000,Z=4.000000)
     AttachRot=(Pitch=22000,Yaw=-16384)
     GearRatio=-2.370000
     Blend=1.000000
     FireModeClass(0)=Class'taskforces.TFHGunFire'
     FireModeClass(1)=Class'taskforces.TFHgunSiegeM'
     PutDownAnim="PutDown"
     SelectSound=Sound'TFMedia.Gunner.HGslct'
     SelectForce="SwitchToMiniGun"
     AIRating=0.710000
     CurrentRating=0.710000
     EffectOffset=(X=100.000000,Y=18.000000,Z=-16.000000)
     DisplayFOV=60.000000
     HudColor=(B=200,G=210)
     InventoryGroup=6
     GroupOffset=1
     PickupClass=class'XWeapons.MinigunPickup'
     PlayerViewOffset=(X=15.000000,Y=-1.000000)
     PlayerViewPivot=(Yaw=500)
     BobDamping=2.250000
     AttachmentClass=Class'taskforces.TFHGunAttach'
     IconMaterial=Texture'HUDContent.Generic.HUD'
     IconCoords=(X1=246,Y1=80,X2=332,Y2=106)
     ItemName="Heavy GatlingGun"
     LightType=LT_Pulse
     LightEffect=LE_NonIncidence
     LightHue=30
     LightSaturation=150
     LightBrightness=150.000000
     LightRadius=4.000000
     LightPeriod=3
     Mesh=SkeletalMesh'Weapons.Minigun_1st'
     DrawScale=0.500000
     DrawScale3D=(Y=1.700000,Z=1.700000)
     Skins(0)=Texture'TFMedia.Gunner.HGTex0'
     UV2Texture=Shader'XGameShaders.WeaponShaders.WeaponEnvShader'
     SoundRadius=400.000000
     HighDetailOverlay=Combiner'UT2004Weapons.WeaponSpecMap2'
     AmmoRegenAmount(0)=20
     SkillCost=250
     StationDmgModifier=10
}
